#include <QCoreApplication>
#include <QLocale>
#include <QTranslator>
#include <QDebug>

#include "setting/JSON_settings.h"
#include "coordinator/coordinator.h"

extern void MessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    qInstallMessageHandler(MessageOutput);

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "rh530_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }

    QCoreApplication::setOrganizationName(SETTING_ORGANIZATION_NAME);
    QCoreApplication::setOrganizationDomain(SETTING_DOMAIN_NAME);
    QCoreApplication::setApplicationName(SETTING_APPLICATION_NAME);

    JSONSettings::Initialize();

    new Coordinator();

    return a.exec();
}
